package com.universe.test;

import java.awt.Graphics;

import javax.measure.quantity.Mass;
import javax.measure.unit.SI;
import javax.swing.JComponent;

import org.jscience.mathematics.vector.DenseVector;
import org.jscience.physics.amount.Amount;

import com.universe.objects.Body;

public class UniverseAdapter extends JComponent{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Universe universe;
	
	private int maxX;
	private int maxY;
	
	public UniverseAdapter(int maxX, int maxY){
		this.maxX = maxX;
		this.maxY = maxY;
		
		Amount<Mass> b1Mass = Amount.valueOf(5.9736E24, SI.KILOGRAM);		
		
		Amount<Mass> b2Mass = Amount.valueOf(7.3477E22, SI.KILOGRAM);
		DenseVector<Amount<?>> b2Position = DenseVector.valueOf(new Amount<?>[]{
				Amount.valueOf(0, SI.METER), Amount.valueOf(362570, SI.KILOMETER)	
		});
		DenseVector<Amount<?>> b2velocity = DenseVector.valueOf(new Amount<?>[]{
				Amount.valueOf(-1022, SI.METERS_PER_SECOND), Amount.valueOf(0, SI.METERS_PER_SECOND)	
		});
		
		universe = new Universe(Amount.valueOf(15, SI.KILOMETER), new Body(b1Mass), new Body(b2Mass, b2Position, b2velocity));
	}
	
	public void iterate(){
		universe.iterate();
	}
	
	public void paint(Graphics g){
		
		for(Body b : universe.getBodies()){
			int x = maxX/2 + (int)b.getPosition().get(0).getEstimatedValue()/4000000;
			int y = maxY/2 - (int)b.getPosition().get(1).getEstimatedValue()/4000000;
			System.out.println("Drawing shape at "+x+"/"+y);
			g.drawOval(x, y, 20, 20);
		}
		
	}
	
}
